package com.zxx.yuanze.lod.answer;

import com.zxx.yuanze.lod.Room;

import java.util.ArrayList;
import java.util.List;

/**
 * LOD
 * @author zxx on 2020/12/8
 */
public class Mediator {

    List<Room> list = new ArrayList<>();

    public Mediator() {
        for (int i = 0; i < 5; i++) {
            list.add(new Room(14 + i, (14 + i) * 150));
        }
    }

    //提取到Mediator里（这就是LOD）
    public Room rentRoom(float area, float price) {
        for (Room room : list) {
            if (isSuitable(area, price, room)) {
                System.out.println("租到房间啦 M! " + room);
                return room;
            }
        }
        return null;
    }

    // 租金要小于等于指定的值,面积要大于等于指定的值
    private boolean isSuitable(float roomArea, float roomPrice, Room room) {
        return room.price <= roomPrice
                && room.area >= roomArea;
    }

}
